Implement graceful shutdown with ConsolePlus.BeginCriticalRender - #13
Merged
Conversation
Console_CancelKeyPress cancelled the token and called Environment.Exit immediately, with no way for in-flight render/cleanup code to finish first. Add ConsolePlus.BeginCriticalRender(), a disposable scope that makes the handler wait up to 300ms after cancelling before forcing the process to exit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Added documentation for ConsolePlus.BeginCriticalRender() in ConsolePlus.md, detailing its purpose, usage, and return value. Updated PromptPlus.csproj to set GeneratePackageOnBuild to true, enabling automatic NuGet package generation during build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new mechanism to safely handle critical render or cleanup sections in the console application, ensuring these sections are given a short grace period to complete when Ctrl+C is pressed before the process exits. This prevents output from being torn down mid-write while still guaranteeing that Ctrl+C will not hang indefinitely. The release version is also incremented.
Critical render/cleanup section handling:
BeginCriticalRender()method toConsolePlus, allowing code to mark a critical section that should be given a short, bounded grace period to finish when Ctrl+C is pressed. The critical section is exited by disposing the returnedIDisposablehandle; nesting is supported. [1] [2]_criticalRenderLock,_criticalRenderIdle, and_criticalRenderCountto track and manage active critical sections.Console_CancelKeyPress) to wait up to 300ms (configurable via_criticalRenderGracePeriod) for in-flight critical render sections to complete before forcing the process to exit, ensuring the application cannot hang indefinitely.Documentation:
BeginCriticalRender()method inConsolePlus.Versioning:
1.0.0-rc2inConsolePlus.csproj.